//
//  NSString+Extension.m
//  XKJY
//
//  Created by xiaokang100 on 2017/1/20.
//  Copyright © 2017年 xiaokang100. All rights reserved.
//

#import "NSString+Extension.h"

@implementation NSString (Extension)
+ (NSString *)jsonToString:(id)data
{
    if(!data) { return nil; }
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:NSJSONWritingPrettyPrinted error:nil];
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

+ (NSString *)changeNumberFormat:(NSString *)number {
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    [formatter setPositiveFormat:@"###,##0.00;"];
    NSNumber *num = [NSNumber numberWithDouble:number.doubleValue];
    NSString *string = [formatter stringFromNumber:num];
    return string;
}

+ (NSString *)wosNumberFormat:(NSString *)number {
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    [formatter setPositiveFormat:@"###,##0;"];
    NSNumber *num = [NSNumber numberWithDouble:number.doubleValue];
    NSString *string = [formatter stringFromNumber:num];
    return string;
}

+ (NSString *)changeNumberFormat:(NSNumberFormatterStyle)formatterStyle withNumber:(NSString *)number {
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    formatter.numberStyle = formatterStyle;
    NSNumber *num = [NSNumber numberWithDouble:number.doubleValue];
    NSString *string = [formatter stringFromNumber:num];
    return string;
}
@end
